/*
 * 2's_complement.c
 *
 *  Created on: Jan 19, 2014
 *      Author: Rohit
 *
 *  This file contains the function used to compute the 2's complement of a given number
 *
 */

//INCLUDES
#include "includes.h"
/*
 * Function : two_complement
 * Input    : 16 bit number of whose 2's complement is to be computed
 * Output	: 2's complement of the number
 *
 * Description:
 * 		2's complement is computed in 2 steps:
		1: Compute the 1's complement
		2: Add 1 to the computed 1's complement
 */

unsigned short get_twos_complement(unsigned short data)
{
	int result_32_bit;
	int result;

	//Ex-ORing with 0xFFFF will compute the 1's complement of the number
	data = data ^ 0xFFFF;
	result_32_bit = data;

	result_32_bit = result_32_bit + 1;

	result = (unsigned short)result_32_bit;

	return result;
}







